Lesson 2

Linear Models - I

Pocket Algorithm

Is much like the max algorithm. We keep running the learning algorithm but keep track of the result with best in sample performance. We then report this result and final result of learning.


In [ ]:

Linear Regression


In [1]:
import numpy as np
import matplotlib.pylab as plt

%matplotlib inline

In [2]:
def regression(X, Y):
    Xd = np.dot(np.linalg.inv(np.dot(X.T, X)), X.T)
    return np.dot(Xd, Y)

In [3]:
Inp = np.array([10, 2, 11, 5, 40, 2, 6, 9]).reshape((4,2))
Out = np.array([5,2,8,1])

In [4]:
X = np.append(np.ones((4,1)), Inp, axis = 1)

In [5]:
W = regression(X,Out)

In [6]:
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(Inp[:,0], Inp[:,1], Out, c='r', marker='o')

plt.show()



In [ ]: